<%-- 
    Document   : newjsp
    Created on : Sep 7, 2014, 5:01:44 PM
    Author     : NGOCLINH-PC
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%@page import="java.sql.*"%> 
        <%
            PreparedStatement st = Connect.Connect.getCon().prepareStatement("SELECT count(*) FROM Event");
            ResultSet rs = st.executeQuery();
            int sohang = 0;
            if (rs.next()) {
                sohang = rs.getInt(1);
            }
            int p = 0;
            String sob = request.getParameter("p");
            if (sob != null) {
                if (sob.equals("0")) {
                    p = 0;
                } else {
                    p = Integer.parseInt(sob) - 1;
                }
            }
            int p_one = 3; // số record
            PreparedStatement st2 = Connect.Connect.getCon().prepareStatement("SELECT * FROM Event ORDER BY EventID DESC LIMIT '" + p + "','" + p_one + "'");
            ResultSet data = st2.executeQuery();
            if (data != null && data.next()) {
                int dem = 0;
                while (data.next()) {
                    dem++;
                    out.print(data.getString("field1") + "<br>"); // show thông tin field có tên là field1
                }
            }
            int i = 0;
            int n = sohang;
            int j = 1;
            int m = p_one;
            for (i = 0; i < n; i++) {
                if (i % m == 0) {
                    if (p >= 0) {
                        if (p + 1 == i) {
                            out.print("<a href=?p=" + i + "><b>" + j + "</b></a> ");
                        } else {
                            out.print("<a href=?p=" + i + ">" + j + "</a> ");
                        }
                    }

                    j++;
                }
            }
        %>
    </body>
</html>
